﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frm供货商修改 : Form
    {
        public frm供货商修改()
        {
            InitializeComponent();
        }
        string str = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
      
        //窗体加载
        private void frm供货商修改_Load(object sender, EventArgs e)
        {
            add();
        }
        public string id;
        //传值
        public void add() {
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            string sql = "select id,idquan,name,appone,phone,beizhu from dbo.jinguocaigou where id='"+id+"'";
            try
            {
                SqlCommand comm = new SqlCommand(sql,conn);
                SqlDataReader reader = comm.ExecuteReader();
                if (reader.Read())
                {
                    this.txtbianhao.Text = reader["id"].ToString();
                    this.txtquanname.Text = reader["idquan"].ToString();
                    this.txtname.Text = reader["name"].ToString();
                    this.txtaddp.Text = reader["appone"].ToString();
                    this.txtbeizhu.Text = reader["beizhu"].ToString();
                    this.txtphone.Text = reader["phone"].ToString();
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally{
                conn.Close();
            
            }
        
        }
        public void xiugai() {
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            try
            {
                string qw1 = this.txtquanname.Text;
                string name = this.txtname.Text;
                string dianhua = this.txtphone.Text;
                string add = this.txtaddp.Text;
                string sql = @"update dbo.jinguocaigou set idquan='" + qw1 + "',name='" + name + "',phone='" + dianhua + "',appone='" + add + "',beizhu='"+this.txtbeizhu.Text+"' where id='" + id + "'";
                SqlCommand comm = new SqlCommand(sql, conn);
                int i = comm.ExecuteNonQuery();
                if (i > 0)
                {
                    MessageBox.Show("修改成功");

                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally {
                conn.Close();
                
            }
        }
        //保存
        private void button1_Click(object sender, EventArgs e)
        {
            xiugai();
         
        }
        //退出
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
